# 以下是linux版本的CMAKE，最后提交的时候交这些，由于windows能够安装的bison版本太低，不支持c++版本，因此需要安装win_flex和win_bison，或者就在虚拟机上完成实验
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
project(Compilerlab3)
set(CMAKE_CXX_STANDARD 14)
add_compile_options(-pedantic)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_BINARY_DIR})
include(FindFLEX)
if(FLEX_FOUND)
 message("Info: flex found!")
else()
 message("Error: flex not found!")
endif()
FLEX_TARGET(Scanner scanner.l ${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp)
include(FindBISON)
if(BISON_FOUND)
 message("Info: bison found!")
else()
 message("Error: bison not found!")
endif()
BISON_TARGET(Parser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
    DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.hpp)
add_executable(Compilerlab3
    ${FLEX_Scanner_OUTPUTS}
    ${BISON_Parser_OUTPUTS}
        starter.cpp
    compilerlab3.cpp
)
target_compile_features(Compilerlab3 PRIVATE cxx_std_14)
target_link_libraries(Compilerlab3 PUBLIC -lm)

# 以下是windows下使用win_flex和win_bison编译的版本

# CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
# project(Compilerlab4)
# set(CMAKE_CXX_STANDARD 14)
# add_compile_options(-pedantic)
# include_directories(${CMAKE_CURRENT_SOURCE_DIR}
# ${CMAKE_CURRENT_BINARY_DIR})
# execute_process(COMMAND
# win_flex -d -o ${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp ${CMAKE_CURRENT_SOURCE_DIR}/scanner.l)

# execute_process(COMMAND
# win_bison -d -o ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/parser.y)
# add_executable(Compilerlab4
#     ${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp
#     ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
#     starter.cpp
#     compilerlab3.cpp
# )
# target_compile_features(Compilerlab4 PRIVATE cxx_std_14)
# target_link_libraries(Compilerlab4 PUBLIC -lm)